<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>赛事视频管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	//url
	var listUrl = '${ctx}/cms/racevideo/';
	var cardUrl = '${ctx}/cms/racevideo/form';

	$(document).ready(function() {

	});
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
	
	function add() { //新增记录
		var url = cardUrl + '?opt=add';
		parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
	}

	function edit(obj, isEdit) { //修改记录
		var curentTr = null;
		if (obj != null) {
			curentTr = jQuery(obj).parents('tr')[0];
		} else {
			var table = jQuery("#contentTable");
			var checkboxs = jQuery('input[name="sort"]:checked', table);
			if (checkboxs.length == 0) {
				alertx("请选择一行数据！");return;
			} else if (checkboxs.length > 1) {
				alertx("只能选择一行数据！");return;
			}
			curentTr = jQuery(checkboxs[0]).parents('tr')[0];
		}
		var id = jQuery('[attrname="id"]', curentTr).val();
		if (id != null || id != '') {
			var opt = (isEdit==true || isEdit == null) ? 'edit' : 'other';
			var url = cardUrl + '?opt=' + opt + '&id=' + id;
			parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
		}
	}
	
	function detail(obj) { //查看记录详情
		edit(obj, false);
	}
	
	function del(obj) { //删除记录
		if (obj != null) { //单个删除
			var curentTr = jQuery(obj).parents('tr')[0];
			var id = jQuery('[attrname="id"]', curentTr).val();
			var url = listUrl + 'delete?id=' + id;
			confirmx('确认要删除该赛事视频吗？', function() {
				window.location.href = url;
			});
		} else { //批量删除
			var table = jQuery("#contentTable");
			var checkboxs = jQuery('input[name="sort"]:checked', table);
			if (checkboxs.length == 0) {
				alertx("请选择至少一行数据！");
				return;
			}
			var ids = [];
			for (var i = 0; i < checkboxs.length; i++) {
				var curentTr = jQuery(checkboxs[i]).parents('tr')[0];
				var id = jQuery('[attrname="id"]', curentTr).val();
				ids.push(id);
			}
			var url = listUrl + 'batchDelete?ids=' + ids.join();
			confirmx('确认要删除所选赛事视频吗？', function() {
				window.location.href = url;
			});
		}
	}

	function resetForm(obj) { //重置查询条件
		var formObj = jQuery(obj).parents('form')[0];
		if (jQuery(formObj)[0] != null) {
			jQuery(formObj)[0].reset();
		}
	}
	
	function clearForm(obj){ //清空查询条件
		var formObj = jQuery(obj).parents('form')[0];
		if (jQuery(formObj)[0] != null) {
			jQuery(formObj).find(':input').each(function(){ 
                switch(this.type){  
                    case 'passsword':  
                    case 'select-multiple':  
                    case 'select-one':  
                    case 'text':  
                    case 'textarea':  
                        $(this).val('');  
                        break;  
                    case 'checkbox':  
                    case 'radio':  
                        this.checked = false;  
                }  
            });     
		}
    }
	
</script>
<style type="text/css">
.tableHead th, td {
	text-align: center;
}
</style>
</head>
<body>
	
	<form:form id="searchForm" modelAttribute="racevideo" action="${ctx}/cms/racevideo/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>编码：</label>
				<form:input path="code" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li><label>名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>简介：</label>
				<form:input path="brefintrol" htmlEscape="false" maxlength="500" class="input-medium"/>
			</li>
			<li class="btns">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnReset" class="btn " type="reset" value="重置" onclick="resetForm(this)"/>
				<input id="btnClear" class="btn " type="button" value="清除" onclick="clearForm(this)"/>
			</li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<div class="" style="margin-bottom: 3px;">
		<shiro:hasPermission name="cms:category:edit">
			<input id="btnAdd" class="btn btn-primary" type="button" value="新 增" onclick="add()"/>&nbsp;
			<input id="btnEdit" class="btn btn-primary" type="button" value="修 改" onclick="edit()"/>&nbsp;
			<input id="btnDel" class="btn btn-primary" type="button" value="删 除" onclick="del()"/>&nbsp;
		</shiro:hasPermission>
		<shiro:hasPermission name="cms:category:view">
			<input id="btnDetail" class="btn " type="button" value="查 看" onclick="detail()"/>&nbsp;
		</shiro:hasPermission>	
	</div>
	<table id="contentTable" class="table table-striped table-bordered table-condensed table-hover">
		<thead>
			<tr class="tableHead">
				<th style="text-align:center;" onclick="toggleCheckBox('checkboxName',this)">
		  			<input type="checkbox" checkboxName="sort" name="table_form_checkbox_all" value="">
		  		</th>
		  		<th style="text-align:center;">序号</th>
				<th>编码</th>
				<th>名称</th>
				<th>简介</th>
				<th>访问次数</th>
				<th>备注信息</th>
				<th>更新时间</th>
				<shiro:hasPermission name="cms:racevideo:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="racevideo"  varStatus="status">
			<tr>
				<td style="text-align:center;" >
					<input type="checkbox" name="sort" attrname="sort" value="">
					<input type="hidden" attrname="id" value="${racevideo.id}"/>
				</td>
				<td style="text-align:center;">
					<span attrname="number">${ status.index + 1}</span>
				</td>
				<td><a  href="javascript:void(0);" onclick="detail(this)">
					${racevideo.code}
				</a></td>
				<td>
					${racevideo.name}
				</td>
				<td>
					${racevideo.brefintrol}
				</td>
				<td>
					${racevideo.hits}
				</td>
				<td>
					${racevideo.remarks}
				</td>
				<td>
					<fmt:formatDate value="${racevideo.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<shiro:hasPermission name="cms:racevideo:edit"><td>
    				<a href="javascript:void(0);" onclick="edit(this)">修改</a>
					<a href="javascript:void(0);" onclick="del(this)">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>